<!DOCTYPE html>
<html xmlns:el-form="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="css/reset.css">
</head>
<body>
<div id="app">
    <el-form :model="addUserFormData" ref="form" :rules="rules" label-width="80px">
        <el-form-item label="用户名" prop="username">
            <el-input type="text" ></el-input>
        </el-form-item>
        <el-form-item label="密码"   prop="password">
            <el-input type="password" v-model.trim="addUserFormData.password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="password_confirm">
            <el-input type="password" v-model.trim="addUserFormData.password_confirm" placeholder="确认密码"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="save()">保存</el-button>
            <el-button @click="formVisible = false" >关闭</el-button>
        </el-form-item>
    </el-form>
</div>

<script src="/js/vue.js"></script>
<script src="/js/elementui.js"></script>
<script>
    var vm = new Vue({
        el:"#app",
        data(){
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.addUserFormData.password) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            };
            return{
                addUserFormData:{
                    password:'',
                    password_confirm:''
                },
                rules:{
                    password_confirm:[
                        {validator: validatePass, trigger: 'blur' }
                    ]
                }
            }
        }
    })
</script>
</body>
</html>
